<?

/**
 * Action collector. 
 * Some modified POJO class to save info about each action from spotlight.xml configuration file.
 *   
 * @package SpotLight.core.configurator.collector
 * @version since begin
 * @author asmhack
 * @license GPL
 * @copyright Serhiy Zaporozhets'
 */
class FlowColl {
   
   private $actions = array ();
   
   private $interceptors = array ();
   
   /**
    * Action name
    *
    * @var string
    */
   private $name ;
   
   /**
    * file to action class.
    *
    * @var string
    */
   private $file ;
   
   
   private $excludes=array();
   
   public function __construct() {
   
   }
   
   public function addInterceptor($interceptor) {
      $this->interceptors [] = $interceptor;
   }
   
   public function getInterceptor() {
      return $this->interceptors;
   }
   
   public function setName($name) {
      $this->name = $name;
   }
   
   public function getName() {
      return $this->name;
   }
   
   public function addAction($action) {
      $this->actions [] = $action;
   }
   
   
   public function addExclude($name) {
      $this->excludes[$name]=1;
   }

   public function isInExcludes($name) {
      return array_key_exists($name,$this->excludes);
   }

   public function getInterceptors() {
      return $this->interceptors;
   }
   
   public function getInterceptorsForExecute($type,$actionName) {
      $ret = array ();
      foreach ( $this->interceptors as $interceptor ) {
         if ($interceptor->checkUrl ($actionName) && $interceptor->isType ( $type )) {
            $ret [] = $interceptor;
         }
      }
      return $ret;
   }
   
   public function getActions() {
      return $this->actions;
   }
   
   /**
    * Return action config object or null;
    *
    * @param string $actionName
    * @return core.collector.Action
    */
   public function getAction($actionName) {
      foreach ( $this->actions as $act ) {
         if (preg_match ( '/^'.$this->name.'\/'. str_replace ( '/', '\/', $act->getName () ) . '/', $actionName, $matches )) 
            return array (0 => $act, 1 => $matches, 2=>true); // 0=> ActionColl object; 1=> array of action's name matches; 2=>is flow's action
      }
      return null;
   }
   
   private function hasInterceptors() {
      return count ( $this->interceptors ) > 0;
   }
   
   public function setFile($file) {
      $this->file = $file;
   }
   
   public function getFile() {
      return $this->file;
   }
   
   public function __toString() {
      $txt = '&nbsp;&nbsp;&nbsp;Flow <b style="color:green">' . $this->name . '</b> {<br/>';
      foreach ( $this->interceptors as $interceptor ) {
         $txt .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $interceptor . '<br/>';
      }
      foreach ( $this->actions as $act ) {
         $txt .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $act . '<br/>';
      }
      $txt .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}';
      return $txt;
   }

}
?>